package ${package.Controller};

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

import com.softWang.common.response.PageBean;
import com.softWang.common.request.Idparam;
import com.softWang.common.response.ResponseResult;
import ${package.Entity}.${entity};
import ${package.ServiceImpl}.${table.serviceImplName};
import ${package.Parent}.vo.${entity?uncap_first}.*;

@Api(value="${entity}管理",tags="${entity}管理")
@Validated
@RestController
@RequestMapping("/${package.ModuleName}/${entity?uncap_first}")
public class ${table.controllerName} {
     @Resource
     private ${table.serviceImplName} ${table.serviceImplName?uncap_first};

     @ApiOperation(value="列表(分页)")
     @RequestMapping(value = "/query", method = RequestMethod.POST)
     public ResponseResult<PageBean<${entity}QueryAllResult>> queryall(@RequestBody @Validated ${entity}QueryAllParam param, HttpServletRequest request) {
         List<${entity}QueryAllResult> results=${table.serviceImplName?uncap_first}.queryall(param);
         PageBean page=new PageBean(results);
         return ResponseResult.success(page);
     }

     @ApiOperation(value="新增")
     //@SysOperationLog(value = "新增", model = SysModel.USER_MANAGE)
     @RequestMapping(value = "/add", method = RequestMethod.POST)
     //@Repeat(message = "重复提交")
     public ResponseResult<Long> add(@RequestBody @Validated ${entity}AddParam param, HttpServletRequest request) throws Exception {
         Long id = ${table.serviceImplName?uncap_first}.add(param);
         return ResponseResult.success(id);
     }

     @ApiOperation(value="修改")
     //@SysOperationLog(value = "修改", model = SysModel.USER_MANAGE)
     @RequestMapping(value = "/edit", method = RequestMethod.POST)
     public ResponseResult<Long> edit(@RequestBody @Validated ${entity}EditParam param, HttpServletRequest request) {
         Long id = ${table.serviceImplName?uncap_first}.edit(param);
         return ResponseResult.success(id);
     }

     @ApiOperation(value="查看详情")
     @RequestMapping(value = "/detail", method = RequestMethod.POST)
     public ResponseResult<${entity}DetailResult> detail(@RequestBody @Validated Idparam idparam) {
         ${entity}DetailResult result = new ${entity}DetailResult();
         ${entity} entity = ${table.serviceImplName?uncap_first}.getById(idparam.getId());
         BeanUtils.copyProperties(entity, result);
         return ResponseResult.success(result);
     }

     @ApiOperation(value="删除")
     //@SysOperationLog(value = "删除", model = SysModel.USER_MANAGE)
     @RequestMapping(value = "/del", method = RequestMethod.POST)
     public ResponseResult del(@RequestBody @NotEmpty(message = "ids 不能为空") <#noparse>List<@NotNull(message = "ids 不能为空") Long></#noparse> ids, HttpServletRequest request) {
         ${table.serviceImplName?uncap_first}.del(ids);
         return ResponseResult.success();
     }
}